class Solution(object):
    def printVertically(self, s):
        s_list = s.split(' ')
        m = max([len(s) for s in s_list])
        n = len(s_list)
        out = [[] for _ in range(m)]
        for i in range(n):
            for j in range(m):
                if j < len(s_list[i]):
                    out[j].append(s_list[i][j])
                else:
                    out[j].append(' ')
        ans = [''] * m
        for i in range(m):
            index = n - 1
            while out[i][index] == ' ':
                index -= 1
            ans[i] = ''.join(out[i])[: index + 1]
        return ans


